import { defineStore } from "pinia";
interface BookInfo{
    bookName:string,
    bookPublic:string,
    bookAuthor:string,
    bookPrice:number,
    bookCount:number,
    bookUrl:string
}

export const useBooksStore = defineStore('booksStore',{
    state:()=>({
        booksInfo:[
            {
                bookName:"少年白马醉春风",
                bookPublic:"北京大学出版社",
                bookAuthor:"不吃香菜",
                bookPrice:49.9,
                bookCount:20,
                bookUrl:"/booksImage/少年白马醉春风.jpg"
            },
            {
                bookName:"静心",
                bookPublic:"文化发展出版社",
                bookAuthor:"梦 芝",
                bookPrice:38.0,
                bookCount:0,
                bookUrl:"/booksImage/静心.jpg"
            },
            {
                bookName:"人间值得",
                bookPublic:"中国华侨出版社",
                bookAuthor:"茗溪",
                bookPrice:5.5,
                bookCount:0,
                bookUrl:"/booksImage/人间值得.jpg"
            },
            {
                bookName:"允许一切发生",
                bookPublic:"天津科学技术出版社",
                bookAuthor:"李梦霁",
                bookPrice:9.9,
                bookCount:56,
                bookUrl:"/booksImage/允许一切发生.jpg"
            },
            {
                bookName:"人性的弱点",
                bookPublic:"中国友谊出版社",
                bookAuthor:"戴尔·卡耐基",
                bookPrice:18.7,
                bookCount:27,
                bookUrl:"/booksImage/人性的弱点.jpg"
            },
            {
                bookName:"被讨厌的勇气",
                bookPublic:"机械工业出版社",
                bookAuthor:"岸见一郎",
                bookPrice:25.8,
                bookCount:47,
                bookUrl:"/booksImage/被讨厌的勇气.jpg"
            },
            {
                bookName:"博弈论",
                bookPublic:"北京联合出版公司",
                bookAuthor:"约翰·纳什",
                bookPrice:68,
                bookCount:83,
                bookUrl:"/booksImage/博弈论.jpg"
            },
                        {
                bookName:"博弈论",
                bookPublic:"北京联合出版公司",
                bookAuthor:"约翰·纳什",
                bookPrice:68,
                bookCount:83,
                bookUrl:"/booksImage/博弈论.jpg"
            },
                        {
                bookName:"博弈论",
                bookPublic:"北京联合出版公司",
                bookAuthor:"约翰·纳什",
                bookPrice:68,
                bookCount:83,
                bookUrl:"/booksImage/博弈论.jpg"
            },
                        {
                bookName:"博弈论",
                bookPublic:"北京联合出版公司",
                bookAuthor:"约翰·纳什",
                bookPrice:68,
                bookCount:83,
                bookUrl:"/booksImage/博弈论.jpg"
            },
                        {
                bookName:"博弈论",
                bookPublic:"北京联合出版公司",
                bookAuthor:"约翰·纳什",
                bookPrice:68,
                bookCount:83,
                bookUrl:"/booksImage/博弈论.jpg"
            },
            
        ] as Array<BookInfo>
    }),
    
    getters:{
        normalBook:(state:any)=>{
            const normal = []
            for(let i=0;i<state.booksInfo.length;i++){
                if(state.booksInfo[i].bookCount >= 20){ normal.push(state.booksInfo[i]) }
            }
            return normal
        },
        warnBook:(state:any)=>{
            const warn = []
            for(let i=0;i<state.booksInfo.length;i++){
                if(state.booksInfo[i].bookCount<10 && state.booksInfo[i].bookCount>0){ warn.push(state.booksInfo[i]) }
            }
            return warn
        },
        lackBook:(state:any)=>{
            const lack = []
            for(let i=0;i<state.booksInfo.length;i++){
                if(state.booksInfo[i].bookCount == 0){lack.push(state.booksInfo[i])}
            }
            return lack
        }
    }

})